Skip to content

fix(types): keep raw_transcription_config values and rebuild transcript.config from them - #288

Open
RishavTiwari25 wants to merge 3 commits into
AssemblyAI:masterfrom
RishavTiwari25:fix/raw-transcription-config
Open

RishavTiwari25 wants to merge 3 commits into
AssemblyAI:masterfrom
RishavTiwari25:fix/raw-transcription-config

Conversation

@RishavTiwari25

Copy link
Copy Markdown

Summary

Two related bugs in TranscriptionConfig / Transcript.config.

1. TranscriptionConfig(raw_transcription_config=raw) erased almost all of raw's values.
The constructor stored raw and then ran every setter (self.language_code = language_code, self.punctuate = punctuate, ...) with the arguments' None defaults, writing straight onto raw. So

raw = aai.RawTranscriptionConfig(language_code="de", punctuate=False)
aai.TranscriptionConfig(raw_transcription_config=raw).language_code  # None

and raw itself was mutated to language_code=None, punctuate=None. The docstring says explicit arguments should take priority over the raw config, not wipe it.

2. transcript.config raised for some completed transcripts.
config_from_response passed the response's fields as TranscriptionConfig(**fields). That breaks when a field's API shape differs from the constructor argument, or the field is not an argument at all:

  • custom_spelling: the API echoes [{"from": [...], "to": "..."}], but set_custom_spelling expects a {to: from} dict -> AttributeError: 'list' object has no attribute 'items'.
  • language_detection_results: a RawTranscriptionConfig field but not a constructor argument -> TypeError: unexpected keyword argument.

Changes

  • assemblyai/types.py: the constructor applies the explicit arguments to a fresh RawTranscriptionConfig, then copies only the non-None ones onto the passed raw_transcription_config (explicit arguments still win) and keeps that object.
  • assemblyai/prerecorded/v2/_base.py: config_from_response builds a RawTranscriptionConfig from the response fields and passes it as raw_transcription_config (this relies on fix 1).
  • assemblyai/__version__.py: 1.8.2 -> 1.8.3 for the version bump check.

Tests

  • tests/unit/test_config.py: raw values are kept (incl. punctuate=False and custom_spelling); explicit arguments override raw values while the rest are kept.
  • tests/unit/test_transcript.py: transcript.config for a response with custom_spelling and one with language_detection_results.

All four fail on master and pass with the fix. pytest tests/unit: 923 passed, 1 failure that also fails on master on Windows (test_upload_request_omits_content_length_for_an_unsized_stream, unrelated). ruff check / ruff format --check clean on the changed files; mypy reports no new errors.

…pt.config from them

TranscriptionConfig(raw_transcription_config=raw) assigned every constructor argument onto raw, so their None defaults erased nearly all of raw's values.

Transcript.config passed the response's fields as constructor arguments, which raised for a transcript with custom_spelling (the API returns a list of from/to objects, the argument is a dict) or language_detection_results (not an argument at all). It now builds a RawTranscriptionConfig and passes that.
Take upstream's assemblyai/__version__.py (1.9.0); the branch's own
1.8.3 bump is superseded.

@ccampbell-aai ccampbell-aai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @RishavTiwari25! A couple of things to fix with your implementation, but this does fix real bugs. Please include a version bump with your changes.

Comment thread assemblyai/types.py
if raw_transcription_config is not None:
# explicit configurations have higher priority if `raw_transcription_config` has been passed as well
for field, value in self._raw_transcription_config:
if value is not None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An explicit False no longer overrides the raw config. For example, set_speaker_diarization store False as None and this copy loop skips over that. Please handle explicit False and add a test for this case.

Comment thread assemblyai/types.py
for field, value in self._raw_transcription_config:
if value is not None:
setattr(raw_transcription_config, field, value)
self._raw_transcription_config = raw_transcription_config

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The caller's raw_transcription_config is still changed in place on these two lines. Copying the object before applying the explicit values would fix this. A test that the caller's object is unchanged will verify.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants